package com.example.carrierapp.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.carrierapp.ui.main.tender.no.TenderNoFragment;
import com.example.carrierapp.ui.main.tender.yes.TenderYesFragment;

public class TenderAdapter extends FragmentPagerAdapter {
    String[] mTitles;
    TenderNoFragment mDispatchDeliveryFragment;
    TenderYesFragment mDispatchHistoryFragment;
    public TenderAdapter(FragmentManager fm, String[] titles) {
        super(fm);
        mTitles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case 1:
                if (mDispatchDeliveryFragment == null) {
                    mDispatchDeliveryFragment = TenderNoFragment.newInstance();
                }
                fragment = mDispatchDeliveryFragment;
                break;
            case 0:
                if (mDispatchHistoryFragment == null) {
                    mDispatchHistoryFragment = TenderYesFragment.newInstance();
                }
                fragment = mDispatchHistoryFragment;
                break;
        }

        return fragment;
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }
}
